package com.serviceribbon.client;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.context.annotation.Bean;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

/**
 * Created by zw on 2017/12/8.
 */
@EnableEurekaClient
@SpringBootApplication
@EnableDiscoveryClient

@RestController
public class RibbonClient {

    @Autowired
    RestTemplate restTemplate;
    public static void main(String[] args) {
        SpringApplication.run(RibbonClient.class,args);
    }

    @RequestMapping("/hi")
    public String hi(@RequestParam String name){
        return restTemplate.getForObject("http://servicetest/hi?name="+name,String.class);
    }

    @Bean
    @LoadBalanced
    RestTemplate restTemplate() {
        return new RestTemplate();
    }
}